package edu.gd.mvndemo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        HttpSession session=req.getSession();
        String username=req.getParameter("name");
        String password=req.getParameter("password");
        PrintWriter out=resp.getWriter();
        if(service.isUser(username,password)){
            session.setAttribute("username",username);
            session.setAttribute("password",password);
            //跳转到某个页面
            resp.sendRedirect(req.getContextPath()+"/houtai.jsp");
        }
        else
            resp.sendRedirect(req.getContextPath()+"/login.jsp");
    }
}
